define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

	$.validator.config({
		rules: {
			priceo: function (element) {
				if(parseFloat($('#c-priceo').val()) < parseInt($('#c-price').val())){
					return '划线价格不能低于当前价格';
				}
				return true
			}
		}
	});
// 监听租赁/销售复选框变化
            $('input[name="row[saletype][]"]').change(function() {
                togglePriceFields();
            });

            // 初始加载时也执行一次
            togglePriceFields();

            function togglePriceFields() {
                var rentChecked = $('#sale-type-rent').is(':checked');
                var saleChecked = $('#sale-type-sale').is(':checked');

                // 控制租金字段显示/隐藏
                if (rentChecked) {
                    $('.rent-field').show();
                } else {
                    $('.rent-field').hide();
                }

                // 控制售价字段显示/隐藏
                if (saleChecked) {
                    $('.sale-field').show();
                } else {
                    $('.sale-field').hide();
                }
            }
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vppz/qxzl/index' + location.search,
                    add_url: 'vppz/qxzl/add?ids='+Config.company_id,
                    edit_url: 'vppz/qxzl/edit',
                    del_url: 'vppz/qxzl/del',
                    multi_url: 'vppz/qxzl/multi',
                    import_url: 'vppz/qxzl/import',
                    table: 'qxzl',
                }
            });

            var table = $("#table");

			var formatter_path=function(value,row,index){
				return '/vp_pz/pages/index/qxzl?svid='+row.id;
			};

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url+'&ids='+Config.company_id,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),searchable:false},
                        {field: 'type', title: '类型', searchList: {"medical_imaging":__('medical_imaging'),"surgical":__('surgical'),"rehabilitation":__('rehabilitation'),"other":__('other')}, formatter: Table.api.formatter.normal},
                        {field: 'name', title: '器械名称', operate: 'LIKE'},
                        {field: 'company.name', title: '所属企业', operate: 'LIKE'},
                        {field: 'image', title: '展示图片', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'price', title:'日租价格', operate:'BETWEEN'},
                        {field: 'yajin', title: '押金', operate:'BETWEEN'},
                        {field: 'saleprice', title: '售价', operate:'BETWEEN'},
                        {field: 'desc', title: '简介', operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        //{field: 'admin_id', title: __('Admin_id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
